package com.neutech.service.impl;

import com.neutech.dao.UserDAO;
import com.neutech.dao.impl.UserDAOImpl;
import com.neutech.entity.User;
import com.neutech.service.UserService;
import com.neutech.vo.ResultVO;

import javax.servlet.http.HttpSession;

public class UserServiceImpl implements UserService {

    private UserDAO userDAO = new UserDAOImpl();

    @Override
    public ResultVO login(User user, HttpSession httpSession) {
        User data = userDAO.getByUsername(user.getUsername());
        if (data == null) {
            return ResultVO.error(3001, "用户不存在");
        }

        if (!data.getPassword().equals(user.getPassword())) {
            return ResultVO.error(3002, "密码不正确");
        }

        // 将用户存储session
        httpSession.setAttribute("user", data);
        return ResultVO.success("登录成功");
    }
}
